var express = require('express');
var path = require('path');

var app = express();

// 记录请求时间的中间件
function logRequestTime(req, res, next) {
    console.log('Received request at ' + new Date());
    next();
}

// 添加中间件到应用程序中
app.use(logRequestTime);

const welcomePage = `
<!DOCTYPE html>
<html>
<head>
  <title>Congratulations｜SAE</title>
  <style>
    .container {
      max-width: 700px;
      margin-left: auto;
      margin-right: auto;
    }
    
    .hero {
      margin-top: 172px;
    }
    
    .hero .message {
      font-size: 15px;
      text-align: center;
      margin-bottom: 24px;
    }
    
    .congrats {
      font-size: 18px;
      font-weight: normal;
      margin-top: 4px;
    }
    
    .details {
      clear: both;
      height: 400px;
      line-height: 1.8;
    }
    
    .callout {
      font-size: 14px;
      color: #1967D2;
      font-weight: 600;
      padding: 16px 24px 16px 40px;
      background-color: #E8F0FE;
      background-position: 16px 16px;
      background-repeat: no-repeat;
      line-height: 1.6;
    }
  </style>
</head>
<body>
  <div class="container">
    <div class="hero">
      <div class="message"> 
        <h1>Congratulations! test ！</h1>
        <div class="congrats">You successfully deployed an application to SAE</div>
      </div>
    </div>
    <div class="details">
      <p class="callout">
        You can deploy any container to Serverless Application Engine that listens for HTTP requests on the port defined by the config.
        Serverless Application Engine will scale automatically based on requests and you never have to worry about infrastructure
      </p>
    </div>
  </div>
</body>
</html>
`

app.get('*', (req, res) => {
    res.send(welcomePage);
})

const port = process.env.FC_CUSTOM_LISTEN_PORT || 9000

app.listen(port, () => {
    console.log('App is listening on port ' + port);
}).on('error', (e) => {
    console.error(e.code, e.message)
})